//
//  UIScrollView+TZExtension.m
//  TZOCExtension
//
//  Created by Tim.Z on 2017/1/3.
//  Copyright © 2017年 Tim.Z. All rights reserved.
//

#import "UIScrollView+TZExtension.h"

@implementation UIScrollView (TZExtension)

- (void)setTz_contentInsetTop:(CGFloat)tz_contentInsetTop
{
    UIEdgeInsets inset = self.contentInset;
    inset.top = tz_contentInsetTop;
    self.contentInset = inset;
}

- (CGFloat)tz_contentInsetTop
{
    return self.contentInset.top;
}

- (void)setTz_contentInsetBottom:(CGFloat)tz_contentInsetBottom
{
    UIEdgeInsets inset = self.contentInset;
    inset.bottom = tz_contentInsetBottom;
    self.contentInset = inset;
}

- (CGFloat)tz_contentInsetBottom
{
    return self.contentInset.bottom;
}

- (void)setTz_contentInsetLeft:(CGFloat)tz_contentInsetLeft
{
    UIEdgeInsets inset = self.contentInset;
    inset.left = tz_contentInsetLeft;
    self.contentInset = inset;
}

- (CGFloat)tz_contentInsetLeft
{
    return self.contentInset.left;
}

- (void)setTz_contentInsetRight:(CGFloat)tz_contentInsetRight
{
    UIEdgeInsets inset = self.contentInset;
    inset.right = tz_contentInsetRight;
    self.contentInset = inset;
}

- (CGFloat)tz_contentInsetRight
{
    return self.contentInset.right;
}

- (void)setTz_contentOffsetX:(CGFloat)tz_contentOffsetX
{
    CGPoint offset = self.contentOffset;
    offset.x = tz_contentOffsetX;
    self.contentOffset = offset;
}

- (CGFloat)tz_contentOffsetX
{
    return self.contentOffset.x;
}

- (void)setTz_contentOffsetY:(CGFloat)tz_contentOffsetY
{
    CGPoint offset = self.contentOffset;
    offset.y = tz_contentOffsetY;
    self.contentOffset = offset;
}

- (CGFloat)tz_contentOffsetY
{
    return self.contentOffset.y;
}

- (void)setTz_contentSizeWidth:(CGFloat)tz_contentSizeWidth
{
    CGSize size = self.contentSize;
    size.width = tz_contentSizeWidth;
    self.contentSize = size;
}

- (CGFloat)tz_contentSizeWidth
{
    return self.contentSize.width;
}

- (void)setTz_contentSizeHeight:(CGFloat)tz_contentSizeHeight
{
    CGSize size = self.contentSize;
    size.height = tz_contentSizeHeight;
    self.contentSize = size;
}

- (CGFloat)tz_contentSizeHeight
{
    return self.contentSize.height;
}

#pragma mark - scrollTo
- (void)tz_scrollToTop {
    [self tz_scrollToTopAnimated:YES];
}

- (void)tz_scrollToBottom {
    [self tz_scrollToBottomAnimated:YES];
}

- (void)tz_scrollToLeft {
    [self tz_scrollToLeftAnimated:YES];
}

- (void)tz_scrollToRight {
    [self tz_scrollToRightAnimated:YES];
}

- (void)tz_scrollToTopAnimated:(BOOL)animated {
    CGPoint off = self.contentOffset;
    off.y = 0 - self.contentInset.top;
    [self setContentOffset:off animated:animated];
}

- (void)tz_scrollToBottomAnimated:(BOOL)animated {
    CGPoint off = self.contentOffset;
    off.y = self.contentSize.height - self.bounds.size.height + self.contentInset.bottom;
    [self setContentOffset:off animated:animated];
}

- (void)tz_scrollToLeftAnimated:(BOOL)animated {
    CGPoint off = self.contentOffset;
    off.x = 0 - self.contentInset.left;
    [self setContentOffset:off animated:animated];
}

- (void)tz_scrollToRightAnimated:(BOOL)animated {
    CGPoint off = self.contentOffset;
    off.x = self.contentSize.width - self.bounds.size.width + self.contentInset.right;
    [self setContentOffset:off animated:animated];
}


@end
